package com.tourlaid.mamagerment.ao.wx.impl

import com.github.pagehelper.Page
import com.github.pagehelper.PageHelper
import com.tourlaid.mamagerment.ao.wx.ScanStoreAo
import com.tourlaid.mamagerment.entity.ResponseData
import com.tourlaid.mamagerment.entity.Store
import com.tourlaid.mamagerment.service.StoreService
import com.tourlaid.mamagerment.vo.StoreListVo
import org.springframework.stereotype.Service
import org.springframework.util.CollectionUtils
import javax.annotation.Resource

/**
 * Created by xiaoyongge on 2017/8/19.
 */
@Service("scanStoreAo")
class ScanStoreAoImpl : ScanStoreAo {

    @Resource
    val storeService: StoreService? = null

    override fun queryHotStore(cityName: String, pageNo: Int): ResponseData<MutableList<StoreListVo>> {
        var list: MutableList<StoreListVo> = mutableListOf()
        var responseData = ResponseData(list)
        PageHelper.startPage<Store>(pageNo, 10, true)
        var page = storeService!!.queryHotStore(cityName) as Page<Store>
        responseData.totalCount = page.getTotal()
        var resultList = page.getResult()
        if (CollectionUtils.isEmpty(resultList)) {
            return responseData
        }
        for (store in resultList) {
            var vo = StoreListVo()
            vo.id = store.id
            vo.storeName = store.storeName
            vo.area = store.area
            vo.image = store.image
            vo.thoughtCount = store.thoughtCount!!
            vo.busiDistrict = store.busiDistrict!!
            list.add(vo)
        }
        responseData.data = list
        return responseData
    }
}